import cv2
import matplotlib.pyplot as plt

imgBGR = cv2.imread("China.jpg", flags = 1)  # flags=1 读取彩色图像(BGR)

plt.subplot(331), plt.title("BGR"), plt.axis('off')
plt.imshow(imgBGR)  # matplotlib显示BGR

plt.subplot(332), plt.title("RGB"), plt.axis('off')
imgRGB = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2RGB)  # BGR--->RGB
plt.imshow(imgRGB)  # matplotlib显示RGB

plt.subplot(333), plt.title("GRAY"), plt.axis('off')
imgGRAY = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2GRAY)  # BGR--->GRAY
plt.imshow(imgGRAY)  # matplotlib显示GRAY

plt.subplot(334), plt.title("HSV"), plt.axis('off')
imgHSV = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2HSV)  # BGR--->HSV
plt.imshow(imgHSV)  # matplotlib显示HSV

plt.subplot(335), plt.title("YCrCb"), plt.axis('off')
imgYCrCb = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2YCrCb)  # BGR--->YCrCb
plt.imshow(imgYCrCb)  # matplotlib显示YCrCb

plt.subplot(336), plt.title("HLS"), plt.axis('off')
imgHLS= cv2.cvtColor(imgBGR, cv2.COLOR_BGR2HLS)  # BGR--->HLS
plt.imshow(imgHLS)  # matplotlib显示HLS

plt.subplot(337), plt.title("XYZ"), plt.axis('off')
imgXYZ= cv2.cvtColor(imgBGR, cv2.COLOR_BGR2XYZ)  # BGR--->XYZ
plt.imshow(imgXYZ)  # matplotlib显示XYZ

plt.subplot(338), plt.title("LAB"), plt.axis('off')
imgLAB= cv2.cvtColor(imgBGR, cv2.COLOR_BGR2LAB)  # BGR--->LAB
plt.imshow(imgLAB)  # matplotlib显示LAB

plt.subplot(339), plt.title("YUV"), plt.axis('off')
imgYUV= cv2.cvtColor(imgBGR, cv2.COLOR_BGR2YUV)  # BGR--->YUV
plt.imshow(imgYUV)  # matplotlib显示YUV

plt.tight_layout() #自动调整子图间距
plt.show()